import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;

/**
 * @author Sprite
 */
public class DbScript {

	public static void main(String[] args) throws SQLException {
		List<Entity> fake_plan = new ArrayList<>();
		List<Entity> duty_plan = Db.use().query("SELECT * FROM duty_plan WHERE grade IN (5,6,7) AND duty_at='2019-09-02 00:00:00'");
		Set<String> distinct = new HashSet<>();
		duty_plan.stream()
			.filter(e -> {
				String staff_id = e.getStr("staff_id");
				String dept_id = e.getStr("dept_id");
				String key = staff_id + "-" + dept_id;
				return distinct.add(key);
			}).forEach(e -> {
			e.set("id",IdUtil.getStrId());
			e.set("duty_at", "2019-09-30 00:00:01");
			e.set("create_at", new Date());
			e.set("update_at", new Date());
			fake_plan.add(e);
		});
		Db.use().insert(fake_plan);
	}

}
